package com.sgb.kjwl.view.ui.activity.self;

import android.content.Context;
import android.content.Intent;

import androidx.databinding.DataBindingUtil;
import androidx.appcompat.app.AppCompatActivity;

import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityApplyCompanyBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.viewmodel.self.ApplyCompanyModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.CommonDialog;
import com.swgk.core.util.MToast;

import javax.inject.Inject;

/**
 * 个人中心-企业信息-申请加入企业
 */
public class ApplyCompanyActivity extends AppActivity {
    public static final int REQUEST_CODE = 101;
    @Inject
    ApplyCompanyModel viewModel;
    private ActivityApplyCompanyBinding binding;
    private String companyNo = "";

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder().appComponent(appComponent).selfModule(new SelfModule(this)).build().inject(this);
    }

    //设置状态栏为暗
    @Override
    protected boolean statusBarDark() {
        return true;
    }

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, ApplyCompanyActivity.class);
        context.startActivity(intent);
    }

    public static void start(Context context, String companyNo) {
        Intent intent = new Intent();
        intent.putExtra("companyNo", companyNo);
        intent.setClass(context, ApplyCompanyActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_apply_company);
        binding.setViewModel(viewModel);
        binding.include.ivBack.setOnClickListener(this);
        binding.include.titleView.setText("企业信息");
        binding.applyView.setOnClickListener(this);
    }

    @Override
    protected void init() {
        companyNo = getIntent().getStringExtra("companyNo");
        viewModel.getCompanyDetailModel(companyNo);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.apply_view:
                ApplyToJoinTheEnterpriseActivity.start(ApplyCompanyActivity.this, viewModel.companyInfoEntity.get().getCompName(),companyNo,1,viewModel.companyInfoEntity.get().getId());
                break;
        }
    }

    private void showTips() {
        if (companyNo.equals("")) {
            MToast.showToast(ApplyCompanyActivity.this, "该企业不存在");
            return;
        }
        new CommonDialog(getActivity()).builder().setPositiveButton("确定").setNegativeButton("取消")
                .setTitle("提示")
                .setMsg("是否确认加入此企业")
                .setDialogCallBack(new CommonDialog.DialogCallBack() {
                    @Override
                    public void onRightClick() {
//                        viewModel.applyCompanyModel(companyNo);
                    }

                    @Override
                    public void onLeftClick() {

                    }
                }).show();
    }
}
